package com.union.vehicleassistant.util;

import com.union.vehicleassistant.R;

/**
 * Created by MrYan on 2018/9/10.
 * 格式枚举
 */

public enum FormatEnum {
    //文件夹
    FOLDER(R.drawable.ic_folder, "folder"),

    //图片格式
    IMG(R.drawable.ic_file_img, "img", "jpg", "jpeg", "gif", "png", "bmp", "tiff"),

    //文本格式
    TXT(R.drawable.ic_file_txt, "txt", "txt"),

    //文档格式
    WORD(R.drawable.ic_file_word, "word", "docx", "dotx", "doc", "dot", "pagers"),

    //电子表格
    EXCEL(R.drawable.ic_file_excel, "excel", "xls", "xlsx", "xlt", "xltx"),

    //ppt
    PPT(R.drawable.ic_file_ppt, "ppt", "ppt", "pptx"),

    //pdf
    PDF(R.drawable.ic_file_pdf, "pdf", "pdf", "PDF", "ofd", "OFD"),

    //音频格式
    MP3(R.drawable.ic_file_audio, "mp3", "mp3", "wav", "wma"),

    //视频格式
    VIDEO(R.drawable.ic_file_video, "video", "avi", "flv", "mpg", "mpeg", "mp4", "3gp", "mov", "rmvb", "mkv"),

    //压缩包
    ZIP(R.drawable.ic_file_zip, "zip", "zip", "jar", "rar", "7z"),

    //未知格式
    UNKNOWN(R.drawable.ic_file_unknow, "unknown");

    public int iconResourceId;
    public String type;
    public String[] formats;


    FormatEnum(String type, String... formats) {
        this.type = type;
        this.formats = formats;
    }

    /**
     * @param type    文件类型
     * @param formats 包含格式
     */
    FormatEnum(int iconResourceId, String type, String... formats) {
        this.iconResourceId = iconResourceId;
        this.type = type;
        this.formats = formats;
    }

    /**
     * 通过文件类型获取对应枚举
     *
     * @param extension 文件扩展名
     * @return 文件对应的枚举信息，如果没有，返回未知
     */
    public static FormatEnum getFormat(String extension) {
        for (FormatEnum format : FormatEnum.values()) {
            for (String extend : format.formats) {
                if (extend.equalsIgnoreCase(extension)) {
                    return format;
                }
            }
        }
        return UNKNOWN;
    }
}
